home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / hamradio / sgp4_pl2.zip / SGP_MATH.PAS < prev    next >
Pascal/Delphi Source File  |  1992-09-28  |  3KB  |  130 lines

  1. Unit SGP_Math;
  2. {           Author:  Dr TS Kelso }
  3. { Original Version:  1991 Oct 30 }
  4. { Current Revision:  1992 Sep 28 }
  5. {          Version:  1.30 }
  6. {        Copyright:  1991-1992, All Rights Reserved }
  7. {$N+}
  8.  
  9. INTERFACE
  10.  
  11. type
  12.   vector = array [1..4] of double;
  13.  
  14. const
  15.   twopi = 2 * pi;
  16.   zero : vector = (0,0,0,0);
  17.  
  18. Function Sign(arg : double) : shortint;
  19. Function Cube(arg : double) : double;
  20. Function Power(arg,pwr : double) : double;
  21. Function Radians(arg : double) : double;
  22. Function Degrees(arg : double) : double;
  23. Function Tan(arg : double) : double;
  24. Function ArcSin(arg : double) : double;
  25. Function ArcCos(arg : double) : double;
  26. Function Modulus(arg1,arg2 : double) : double;
  27. Function Fmod2p(arg : double) : double;
  28. Function AcTan(sinx,cosx : double) : double;
  29. Function Dot(v1,v2 : vector) : double;
  30. Procedure Magnitude(var v : vector);
  31. Procedure Cross(v1,v2 : vector; var v3 : vector);
  32.  
  33. IMPLEMENTATION
  34.  
  35. Function Sign(arg : double) : shortint;
  36.   begin
  37.   if arg > 0 then
  38.     Sign := 1
  39.   else if arg < 0 then
  40.     Sign := -1
  41.   else
  42.     Sign := 0;
  43.   end; {Function Sign}
  44.  
  45. Function Cube(arg : double) : double;
  46.   begin
  47.   Cube := arg*Sqr(arg);
  48.   end; {Function Cube}
  49.  
  50. Function Power(arg,pwr : double) : double;
  51.   begin
  52.   if arg > 0 then
  53.     Power := Exp(pwr*Ln(arg))
  54.   else
  55.     Writeln(output,'Invalid argument in Function Power!');
  56.   end; {Function Power}
  57.  
  58. Function Radians(arg : double) : double;
  59.   begin
  60.   Radians := arg*pi/180;
  61.   end; {Function Radians}
  62.  
  63. Function Degrees(arg : double) : double;
  64.   begin
  65.   Degrees := arg*180/pi;
  66.   end; {Function Degrees}
  67.  
  68. Function Tan(arg : double) : double;
  69.   begin
  70.   Tan := Sin(arg)/Cos(arg);
  71.   end; {Function Tan}
  72.  
  73. Function ArcSin(arg : double) : double;
  74.   begin
  75.   ArcSin := ArcTan(arg/Sqrt(1-Sqr(arg)));
  76.   end; {Function ArcSin}
  77.  
  78. Function ArcCos(arg : double) : double;
  79.   begin
  80.   ArcCos := pi/2 - ArcSin(arg);
  81.   end; {Function ArcCos}
  82.  
  83. Function Modulus(arg1,arg2 : double) : double;
  84.   var
  85.     modu : double;
  86.   begin
  87.   modu := arg1 - Trunc(arg1/arg2) * arg2;
  88.   if modu >= 0 then
  89.     Modulus := modu
  90.   else
  91.     Modulus := modu + arg2;
  92.   end; {Function Modulus}
  93.  
  94. Function Fmod2p(arg : double) : double;
  95.   begin
  96.   Fmod2p := Modulus(arg,twopi);
  97.   end; {Function Fmod2p}
  98.  
  99. Function AcTan(sinx,cosx : double) : double;
  100.   begin
  101.   if cosx = 0 then
  102.     if sinx > 0 then
  103.       Actan := pi/2
  104.     else
  105.       Actan := 3*pi/2
  106.   else if cosx > 0 then
  107.     Actan := ArcTan(sinx/cosx)
  108.   else
  109.     Actan := pi + ArcTan(sinx/cosx);
  110.   end; {Function Actan}
  111.  
  112. Function Dot(v1,v2 : vector) : double;
  113.   begin
  114.   Dot := v1[1]*v2[1] + v1[2]*v2[2] + v1[3]*v2[3];
  115.   end;  {Function Dot}
  116.  
  117. Procedure Magnitude(var v : vector);
  118.   begin
  119.   v[4] := Sqrt(Sqr(v[1]) + Sqr(v[2]) + Sqr(v[3]));
  120.   end; {Procedure Magnitude}
  121.  
  122. Procedure Cross(v1,v2 : vector; var v3 : vector);
  123.   begin
  124.   v3[1] := v1[2]*v2[3] - v1[3]*v2[2];
  125.   v3[2] := v1[3]*v2[1] - v1[1]*v2[3];
  126.   v3[3] := v1[1]*v2[2] - v1[2]*v2[1];
  127.   end; {Procedure Cross}
  128.  
  129. end.
  130.